// Fill out your copyright notice in the Description page of Project Settings.


#include "Characters/Combat//CombatComponent.h"

#include "Characters/Combat//CombatManager.h"

// Sets default values for this component's properties
UCombatComponent::UCombatComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UCombatComponent::BeginPlay()
{
	Super::BeginPlay();

	// ...
	SwitchCombatScheme(CurrentWeaponType);
	
}


// Called every frame
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}

void UCombatComponent::SwitchCombatScheme(EWeaponType TargetWeaponType)
{
	ACombatManager* PlayerCombatManager = ACombatManager::Get();
	const UDataTable* CombatSchemesDataTable = PlayerCombatManager->GetCombatSchemesDataTable();
	TArray<FName> RowNames = CombatSchemesDataTable->GetRowNames();
	for(FName& RowName: RowNames)
	{
		FCombatScheme* Row = CombatSchemesDataTable->FindRow<FCombatScheme>(RowName, TEXT(""));
		if(Row)
		{
			if(Row->WeaponType== TargetWeaponType)
			{
				CombatScheme = *Row;
				break;
			}
		}
	}
	
	CurrentWeaponType = TargetWeaponType;
}

